#include "WProgram.h"
#include <string.h>
#include "Song.cpp"

/**
 * Song Implementation for Party Sense Library
 *
 * Authors:
 * Arjun Sinha
 * Rajeev Krithivasan
 * Will Sergeant
 **/

Song::Song(String title, String artist, Phone p){
	_title = title;
	_artist = artist;
	_playCount = 0;
	_phoneCount = 0;
	
	addPhone(p);
}

void Song::played(){
	_playCount++;
}

void Song::resetPlayCount(){
	_playCount = 0;
}

int Song::getPlayCount(){
	return _playCount;
}

int Song::getPhoneCount(){
	return _phoneCount;
}

boolean Song::addPhone(Phone p){
	if (phoneCount >= PHONE_LIST_LEN){
		return false;
	}
	else{
		_phones[phoneCount] = p;
		phoneCount++;
	}
}

boolean Song::removePhone(Phone p){
	for (int i = 0; i < phoneCount; i++){
		if (string::compare(_phones[i].address, p.address) == 0){
			for (int j = i; j < phoneCount-1; j++){
				_phones[j] = _phones[j+1];	//shift entries
			}
			_phones[phoneCount] = NULL;	//null out last cell
			phoneCount--;				//decrement count
			return true;
		}
	}
	return false;
}

Phone Song::getPhone(int i){
	if (i < 0 || i >= phoneCount){
		return NULL;
	}
	return _phones[i];
}
